﻿@using KRM.Core
@model IEnumerable<KRM.Core.tblRDMQuestionnaireQuestion>
@{
    KRM.Core.tblRDMQuestionnaire questionnaire = ViewBag.Questionnaire;
}
<script>
    $(document).ready(function () {
        $(".cbCheckQuestion").change(function () {
            if ($(this).is(':checked')) {
                $(this).parent().parent().parent().parent().find($("textarea")).removeAttr('disabled');
            } else {
                $(this).parent().parent().parent().parent().find($("textarea")).attr('disabled', 'disabled');
            }
            if ($("#ReasonID").val() == 23) {
                $("textarea[name='t14']").attr("required", "required");
            } else {
                $("textarea[name='t14']").removeAttr("required");
            }
        });
        $(".cbcheck").change(function () {
            if ($("#ReasonID").val() == 8) {
                if ($(this).val() == "No") {
                    var reasonDetail = $("#ReasonDetailID").val();
                    if (reasonDetail != 242 || reasonDetail != 244 || reasonDetail != 245) {
                        alert('THIS RDM CAN NOT BE AUTHOURISED WITHOUT THIS');
                        $(".btn-generaterdm, .btn-addquestionnaire").attr('disabled', 'disabled');
                    }
                } else {
                    $(".btn-generaterdm, .btn-addquestionnaire").removeAttr('disabled');
                    $.each($(".checklistquestionnaire .cbcheck"), function () {
                        if ($(this).is(':checked')) {
                            if ($(this).val() == "No") {
                                $(".btn-generaterdm, .btn-addquestionnaire").attr('disabled', 'disabled');
                            }
                        }
                    });
                }
            }
        });
    });
</script>
@if (questionnaire != null)
{
    var db = new KRMEntities();
    foreach (var item in questionnaire.RdmQuestionnaireAnswers)
    {
        var question = db.tblRDMQuestionnaireQuestions.Find(item.QuestionID);
        
    <div>
        <div class="row-fluid">
            <div class="span1">@(question.Position). </div>
            <div class="span11">
                <label>
                    @if (question.ReasonID != 8)
                    {
                        <input type="checkbox" name="@item.QuestionID" value="True" class="pull-left cbCheckQuestion" style="margin-right: 7px" required="required" @(item.IsChecked == true ? "checked=checked" : "") />
                    }
                    @question.QuestionText
                </label>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span1"></div>
            <div class="span11">
                @if (question.ReasonID == 8 && question.Position == 2 || question.Position == 3)
                {
                    <div class="span10">
                        <label class="pull-left" style="margin-right: 20px">
                            <input type="radio" name="t@(item.QuestionID)" value="Yes" class="cbcheck" @(item.Comment == "Yes" ? "checked=checked" : "") />Yes</label>
                        <label>
                            <input type="radio" name="t@(item.QuestionID)" value="No" class="cbcheck" @(item.Comment == "No" ? "checked=checked" : "") />
                            No</label>
                    </div>
                }
                else if (question.ReasonID == 8 && question.Position == 1)
                {
                    <div class="span2">Reason</div>
                    <div class="span4">
                        <select class="input-block-level" name="t@(question.QuestionID)">
                            <option value="Quality" @(item.Comment == "Quality" ? "selected=selected" : "")>Quality</option>
                            <option value="Size" @(item.Comment == "Size" ? "selected=selected" : "")>Size</option>
                            <option value="Missing Parts" @(item.Comment == "Missing Parts" ? "selected=selected" : "")>Missing Parts</option>
                            <option value="Damaged Parts" @(item.Comment == "Damaged Parts" ? "selected=selected" : "")>Damaged Parts</option>
                            <option value="Delivery Issue" @(item.Comment == "Delivery Issue" ? "selected=selected" : "")>Delivery Issue</option>
                            <option value="Unwanted" @(item.Comment == "Unwanted" ? "selected=selected" : "")>Unwanted</option>
                            <option value="Incorrect Item" @(item.Comment == "Incorrect Item" ? "selected=selected" : "")>Incorrect Item</option>
                            <option value="Not As Expected" @(item.Comment == "Not As Expected" ? "selected=selected" : "")>Not As Expected</option>
                        </select>
                    </div>
                }
                else
                {
                    <div class="span2">Comment</div>
                    <div class="span10">
                        <textarea class="input-block-level aaa" name="t@(question.QuestionID)">@item.Comment</textarea>
                    </div>
                }

            </div>
        </div>
    </div>
    }
}
else
{
    foreach (var item in Model)
    {
    <div>
        <div class="row-fluid">
            <div class="span1">@(item.Position). </div>
            <div class="span11">
                <label>
                    @if (item.ReasonID != 8)
                    {
                        <input type="checkbox" name="@item.QuestionID" value="True" class="pull-left cbCheckQuestion" style="margin-right: 7px" required="required" />
                    }
                    @item.QuestionText
                </label>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span1"></div>
            <div class="span11">
                @if (item.ReasonID == 8 && item.Position == 2 || item.Position == 3)
                {
                    <div class="span10">
                        <label class="pull-left" style="margin-right: 20px">
                            <input type="radio" name="t@(item.QuestionID)" value="Yes" checked="checked" class="cbcheck" />Yes</label>
                        <label>
                            <input type="radio" name="t@(item.QuestionID)" value="No" class="cbcheck" />
                            No</label>
                    </div>
                }
                else if (item.ReasonID == 8 && item.Position == 1)
                {
                    <div class="span2">Reason</div>
                    <div class="span4">
                        <select class="input-block-level" name="t@(item.QuestionID)">
                            <option value="Quality">Quality</option>
                            <option value="Size">Size</option>
                            <option value="Missing Parts">Missing Parts</option>
                            <option value="Damaged Parts">Damaged Parts</option>
                            <option value="Delivery Issue">Delivery Issue</option>
                            <option value="Unwanted">Unwanted</option>
                            <option value="Incorrect Item">Incorrect Item</option>
                            <option value="Not As Expected">Not As Expected</option>
                        </select>
                    </div>
                }
                else
                {
                    <div class="span2">Comment</div>
                    <div class="span10">
                        <textarea class="input-block-level aaa" name="t@(item.QuestionID)" disabled="disabled"></textarea>
                    </div>
                }

            </div>
        </div>
    </div>
    }
}